<!-- Student_studyWindow.html -->
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
		<meta name="format-detection" content="telephone=no, email=no, date=no, address=no">
		<title>学习首页</title>
	   <link rel="stylesheet" href="../../css/mui.min.css">
<!--      <link rel="stylesheet" href="../../css/CFNetPP_Base.css">-->
      <link rel="stylesheet" href="../../css/base.css">
		<style type="text/css" media="screen">
			/*.base_right_item {
				width: 80px;
				text-align: center;
			}
			.top-segment-div:before{
			    position: absolute;
			    right: 0;
			    top: 103px;
			    left: 0;
			    height: 1px;
			    content: '';
			    -webkit-transform: scaleY(.5);
			    transform: scaleY(.5);
			    background-color: #c8c7cc;
			}*/
			.nav-right-img{
	            width: 24px;
	            margin-left: 12px;
	            margin-top: 8px;
	        }
	        .nav-right-scan-img{
	            width: 20px;
	            margin-left: 14px;
	            margin-top: 12px;
	        }
			/*.redPointMessage{
				width: 8px;
				height: 8px;
				 top: 4px;
				 left: 30px;
				 right: 0px;
			 }*/
				.redPointMessage{
				width: 8px;
				height: 8px;
				 top: 4px;
				 left: 30px;
				 right: 0px;
			 }
		</style>
	</head>
	<body>
		<div  id='BarAppearance'></div>
		<div class="base_navigation_bar base_style_color">
			<a class="base_left_item" href="#" onclick="backClick()"> <img class="base_back_icon" src="../../image/icon_jiantou.png" alt=""> </a>
			<span id="nav_title"></span>
			<!--<a class="base_right_item" onclick="toMessageClick()" style="position:relative;">

				<div id="redPointMessage" class="redPointMessage"></div>
	            <img id="msg_img" class="nav-right-img" src="../../image/icon_msg_message.png" alt="">
	        </a>-->
			<div class="base_right_item nav-item" style="margin-right: 10px;padding:5px;width: auto;background-color: #F8575D;height: auto;top: 50%;position: relative;transform:translate(0,-50%)"  onclick="joinClass()">+申请加入课堂</div>
<!--	        <a class="base_right_item nav-item" onclick="joinClass()" style="background-color:red;position:relative;width: auto;line-height: 44px" >-->
<!--	           <span>+申请加入课堂</span>-->

<!--	        </a>-->
		</div>
		<!-- <div class="base_content_div">
			<div class="bgwhite top-segment-div" style="padding: 10px 10px;">
				<div id="segmentedControl" class="mui-segmented-control">
					<a id="item0" class="segment_item mui-control-item mui-active" href="#" onclick="itemClick(0)"> 我的课程 </a>
					<a id="item1" class="segment_item mui-control-item" href="#"  onclick="itemClick(1)"> 历史课程 </a>
				</div>
			</div>
		</div> -->
	</body>
	<script src="../../script/api.js" type="text/javascript"></script>
	<script src="../../script/jquery.min.js" type="text/javascript"></script>
	<script type="text/javascript" src="../../script/requestTool.js"></script>
	<script src="../../script/ui.js"></script>
	<script>
		apiready = function() {
			initHeaderUI();
		    setupNavTitle();
			// setupCourseFrameGroup();
			setupCourseFrame();
			setupMsgBtnStatus();
			setupNotifi();
		};
		function setupNavTitle(){
			if ($api.getStorage('cfnetSelectType') == 1) {//老师
				$('#nav_title').text('课程');
			}else{
				$('#nav_title').text('学习');
			}
		}
		function setupCourseFrame(){
			var y = $('#BarAppearance').height() + $('.base_navigation_bar').height();
			var h = api.winHeight - y;
			// if ($api.getStorage('cfnetppjxid') == 333){
	            // h -= 52;
	        // }
			var rect = {
				x : 0,
				y : y,
				w : 'auto',
				h : h
			}
			api.openFrame({
			    name: 'Student_studyCourseList',
			    url: 'Student_studyCourseList.html',
			    rect: rect,
			    pageParam: {
					courseType : 1,
					sourceurl : window.location.pathname,
					sourcetitle : document.title,
					ifteacherstudy:api.pageParam.ifteacherstudy,//是否是老师端学习
					openType : api.pageParam.openType
				}
			});
		    sendBuriedNotifi(0,'课程列表','006')
			// if (api.pageParam.Type == 1) {
			// 	hideCourseFrame();
			// }
		}
		function sendBuriedNotifi(busionessid,pagetype,pagetypeid){
		    var userinfo = {
				uid : $api.getStorage('cfnetppuid'),
				jid : $api.getStorage('cfnetppjxid'),
				uname : $api.getStorage('cfnetppusername'),
			}
			var data = {
				busionessid : busionessid,
				pagetype : pagetype,
				pagetypeid : pagetypeid,
				sourceurl : api.pageParam.sourceurl,
				sourcetitle : api.pageParam.sourcetitle,
				accesspageurl :  window.location.pathname,
				accesspagetitle : document.title,
				userinfo : userinfo
			}
			SendBehaviorTrajectoriesNotifi_Study(data);
		}
		
		
		function setupCourseFrameGroup() {
			var y = $('.base_navigation_bar').height() + $('.base_content_div').height();
			var h = api.winHeight - y - 52;
			var rect = {
				x : 0,
				y : y,
				w : 'auto',
				h : h
			}
			api.openFrameGroup({
				name : 'StudyCourseFrameGroup',
				rect : rect,
				scrollEnabled : false,
				frames : [{
					name : 'Student_studyCourseList',
					url : 'Student_studyCourseList.html',
					pageParam : {
						courseType : 1
					}
				}, {
					name : 'Student_studyHistoryList',
					url : 'Student_studyHistoryList.html'
				}]
			}, function(ret, err) {
			});
			if (api.pageParam.Type == 1) {
				hideCourseFrameGroup();
			}
		}

		function showCourseFrameGroup() {
			api.setFrameGroupAttr({
				name : 'StudyCourseFrameGroup',
				hidden : false
			});
		}

		function hideCourseFrameGroup() {
			api.setFrameGroupAttr({
				name : 'StudyCourseFrameGroup',
				hidden : true
			});
		}
		function showCourseFrame(){
		    
		
			api.setFrameAttr({
			    name: 'Student_studyCourseList',
			    hidden: false
			});
		
		}
		function hideCourseFrame(){
			api.setFrameAttr({
			    name: 'Student_studyCourseList',
			    hidden: true
			});
		}
		function itemClick(itemIndex) {
			if (!$('#item' + itemIndex).hasClass('mui-active')) {
				$('.segment_item').removeClass('mui-active');
				$('#item' + itemIndex).addClass('mui-active');
				setupGroupIndex(itemIndex);
			}
		}

		function setupGroupIndex(index) {
			api.setFrameGroupIndex({
				name : 'StudyCourseFrameGroup',
				index : index,
				scroll : false
			});
		}

		function setupNotifi() {
			api.addEventListener({
				name : 'showCourseFrameGroupNotifi'
			}, function(ret, err) {
				// showCourseFrameGroup();
		
				// showCourseFrame();
			});
			api.addEventListener({
				name : 'hideCourseFrameGroupNotifi'
			}, function(ret, err) {
				// hideCourseFrameGroup();
				// hideCourseFrame();
			});
			api.addEventListener({
	            name: 'pushMessage'
	        }, function(ret, err) {
	            pushMessage();
	        });
	        api.addEventListener({
	            name: 'viewappear'
	        }, function(ret, err) {
	            setupMsgBtnStatus();
	        });
		}
		//push 消息提醒
	    function pushMessage() {
	        var jid = $api.getStorage('cfnetppjxid');
	        var msgVal = $api.getStorage('cfnetppmessagexuexi' +　jid);
	        // console.log("msgVal : " + msgVal);
	        if (msgVal == 1) {
                $('#redPointMessage').show();
            }else{
                $('#redPointMessage').hide();
            }
	    }
	    function backClick(){
	    	sendBuriedNotifi(1,'课程列表','006')
			api.closeWin();
	    }
		function backIndex() {
		   sendBuriedNotifi(1,'课程列表','006')
			api.closeToWin({
				name : 'index'
			});
		}
		function setupMsgBtnStatus(){
			api.sendEvent({
	            name: 'click_pushMessage_index'
	        });
	        
//          pushMessage();
	    }
	    function toMessageClick(){
	        api.openWin({useWKWebView:true,
	            name: 'Student_MessageWin',
	            url: 'Student_MessageWin.html',
	            pageParam : {
                    cid:'',
					sourceurl : window.location.pathname,
		            sourcetitle : document.title,
		            
                }
	        });
	        sendBuriedNotifi(1,'课程列表','006')
	    }
	    function toScanClick(){
            var systemType = api.systemType;
            if (systemType == 'ios') {
                return;
            }
            var Scan = api.require('Scan');
            var param = {
                name : "111"
            };
            Scan.showScan(param, function (ret, err) {
                    console.log("data : " + JSON.stringify(ret));
                    var url = eval('(' + ret.result + ')').url;
                    if (url != undefined && checkURL(url)) {
                        var title = eval('(' + ret.result + ')').title;
                        console.log("data url : " + url);
                        var pageParam = {
                            url: url,
                            title: title,
                            shareurl : url
                        };
                        api.openWin({useWKWebView:true,
                            name: 'indexLunDetailsWindow',
                            url: '../HomePage/indexLunDetailsWindow.html',
                            pageParam: pageParam
                        });
                    }
            });
	    }
        function checkURL(URL) {
            var str = URL;
//判断URL地址的正则表达式为:http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?
//下面的代码中应用了转义字符"\"输出一个字符"/"
            var Expression = /http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?/;
            var objExp = new RegExp(Expression);
            if (objExp.test(str) == true) {
                return true;
            } else {
                return false;
            }
        }
        function joinClass() {
			api.openWin({useWKWebView:true,
				name: 'joinClass',
				url: 'joinClass.html',
			});
		}
	</script>
</html>